package cn.itshare.junit.init;


import java.util.Date;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.itshare.junit.test.InitData;

import com.share.bean.oa.org.Department;
import com.share.bean.oa.org.EmpAccount;
import com.share.bean.oa.org.Employee;
import com.share.bean.oa.org.Organization;
import com.share.commons.enumeration.Gender;
import com.share.commons.util.RandomUtil;
import com.share.service.oa.org.DepartmentManager;
import com.share.service.oa.org.EmployeeManager;
import com.share.service.oa.org.OrganizationManager;

/**
 * 人力资源初始化数据 （机构，部门，员工）
 * @author Administrator
 *
 */
public class OAHR_org_dept_emp {
	
	private OrganizationManager om ;
	private DepartmentManager dm ;
	private EmployeeManager em ;
	
	@Before
	public void setUp() throws Exception {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring/bean*.xml") ;
		om = (OrganizationManager) ctx.getBean("organizationManagerImpl") ;
		dm = (DepartmentManager) ctx.getBean("departmentManagerImpl") ;
		em = (EmployeeManager) ctx.getBean("employeeManagerImpl") ;
	}
	
	@Test
	public void testOrg() throws Exception {
		
		for(int i=1; i<5; i++) {
			Organization o = new Organization() ;
			o.setOrgCode(RandomUtil.getRandomNum(9)) ;
			o.setOrgLegalName("机构名称【"+ InitData.data("name",4) +"】") ;
			o.setOrgLegalPeople("【"+ InitData.data("name",3) +"】") ;
			o.setOrgZip(RandomUtil.getRandomNum(6)) ;
			o.setOrgSynopsis("无简介") ;
			o.setEstablishCountry("2010-0"+i+"-0"+i) ;
			o.setOrgBak("无备注") ;
			o.setOrgAddr(InitData.data("name",10)) ;
			o.setAddTime(new Date()) ;
			o.setEstablishTime(new Date()) ;
			
			om.saveOrgManager(o) ;
			
			for(int j=1; j<15; j++) {
				Department d = new Department() ;
				d.setDeptNo(RandomUtil.getRandomNum(9)) ;
				d.setDeptName("【"+ InitData.data("name",4) +"】");
				d.setDeptContactPeople("【"+ InitData.data("name",3) +"】") ;
				d.setDeptCreTime(new Date()) ;
				d.setDeptContactTel(RandomUtil.getRandomNum(11)) ;
				d.setDeptBak("无备注") ;
				d.setOrganization(o) ;
				
				dm.saveDeptManager(d) ;
				
				for(int k=1; k<20; k++) {
					Employee e = new Employee() ;
					e.setEmpNo(RandomUtil.getRandomNum(9)) ;
					e.setEmpRealname(InitData.data("name",3)) ;
					e.setNation(InitData.data("name",1)+"族") ;
					e.setGender(Gender.WOMAN) ;
					e.setBirthday(new Date()) ;
					e.setTel(RandomUtil.getRandomNum(11)) ;
					e.setEmail(RandomUtil.getRandomString(7)+"@126.com") ;
					e.setAppointmentDate(new Date()) ;
					e.setVisible(true) ;
					
					EmpAccount ec = new EmpAccount() ;
					ec.setAccount(RandomUtil.getRandomNum(3)) ;
					ec.setPassword(RandomUtil.getRandomNum(3)) ;
					//账号
					e.setEmpAccount(ec) ;
					//部门
					e.setDepartment(d) ;
					
					em.saveEmpManager(e) ;
				}
			}
		}
	}

}
